package com.dzl.enterprise.service.impl;

import com.dzl.base.service.BaseServiceImpl;
import com.dzl.enterprise.dao.WelfareEnterpriseConfigMapper;
import com.dzl.enterprise.pojo.WelfareEnterpriseConfig;
import com.dzl.enterprise.service.WelfareEnterpriseConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 企业独立部署小程序配置信息(welfare_enterprise_config)表服务实现类
 * @author liuguanjun
 * @date 2022-02-14 16:23:23
 */
@Slf4j
@Service
public class WelfareEnterpriseConfigServiceImpl extends BaseServiceImpl<WelfareEnterpriseConfig> implements WelfareEnterpriseConfigService {

    @Autowired
    private WelfareEnterpriseConfigMapper mapper;


    @Override
    public WelfareEnterpriseConfig getWelfareEnterpriseConfigByEnterpriseId(Integer enterpriseId) {
        WelfareEnterpriseConfig welfareEnterpriseConfigQuery = new WelfareEnterpriseConfig();
        welfareEnterpriseConfigQuery.setEnterpriseId(enterpriseId);
        return mapper.selectOne(welfareEnterpriseConfigQuery);
    }

    @Override
    public Integer saveWelfareEnterpriseConfig(WelfareEnterpriseConfig welfareEnterpriseConfig) {
        WelfareEnterpriseConfig welfareEnterpriseConfigQuery = new WelfareEnterpriseConfig();
        welfareEnterpriseConfigQuery.setEnterpriseId(welfareEnterpriseConfig.getEnterpriseId());
        int count = mapper.selectCount(welfareEnterpriseConfigQuery);
        if(count>0){
            WelfareEnterpriseConfig welfareEnterpriseConfig1 = mapper.selectOne(welfareEnterpriseConfigQuery);
            welfareEnterpriseConfig.setId(welfareEnterpriseConfig1.getId());
            return mapper.updateByPrimaryKeySelective(welfareEnterpriseConfig);
        }else{
            return mapper.insertSelective(welfareEnterpriseConfig);
        }
    }
}
